public class MyQueue {

    static class ListNode {
        public int val;
        public ListNode prev;
        public ListNode next;

        public ListNode(int val) {
            this.val = val;
        }
    }

    public ListNode first = null;
    public ListNode last = null;

    public int usedSize = 0;

    public void offer(int val) {
        ListNode cur = new ListNode(val);
        if (last == null) first = last = cur;
        else {
            last.next = cur;
            cur.prev = last;
            last = cur;
        }
        usedSize++;
    }

    public int poll() {
        usedSize--;
        if (first == null) {

            return -1;
        } else {
            int val = first.val;
            first = first.next;
            if (first != null)
                first.prev = null;
            return val;
        }
    }

    public int peek() {
        if (first == null) {
            return -1;
        } else {
            return first.val;
        }

    }

    public boolean isEmpty() {
        return first == null;
    }

}
